package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-09 18:10
 **/
public class LeetCode2129 {

    public static String capitalizeTitle(String title) {
        String[] strs = title.split(" ");
        StringBuilder builder = new StringBuilder();
        for (String s : strs) {
            char[] chars = s.toCharArray();

            for (int i = 0; i < chars.length; ++i) {
                chars[i] = Character.toLowerCase(chars[i]);
            }

            if (chars.length > 2) {
                chars[0] = Character.toUpperCase(chars[0]);
            }

            s = String.valueOf(chars);
            builder.append(s).append(" ");
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }

}
